package com.await.health;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

/**
 * @author HuangLiang
 */
public class MainActivity extends AppCompatActivity {
    final String[] doctors = new String[]{"HuaTuo","Zhang","Bai"};
    private Button docSelect;
    private EditText docName;
    private AlertDialog.Builder builder;
    private AlertDialog alertDialog;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        // init
        init();
        builder = new AlertDialog.Builder(MainActivity.this);
        docSelect.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                alertDialog = builder.setTitle("please select doctor")
                        .setSingleChoiceItems(doctors, 0, new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                docName.setText(doctors[i]);
                                alertDialog.hide();
                                alertDialog.dismiss();
                            }
                        }).create();
                alertDialog.show();
            }
        });
    }

    /**
     * init
     */
    public void init(){
        docSelect = findViewById(R.id.doc_select);
        docName = findViewById(R.id.doc_name);
    }
}